[broadway] Fix up frame size calculation
authorAlexander Larsson <alexl@redhat.com>
Mon, 11 Apr 2011 08:42:03 +0000 (10:42 +0200)
committerAlexander Larsson <alexl@redhat.com>
Mon, 11 Apr 2011 10:09:43 +0000 (12:09 +0200)
Turns out that offsetTop/Left doesn't contain the border, so we need
to manually add that in.

gdk/broadway/broadway.js

index 8cefb061c420dfbd0dc88edc651290777ebd1b1a..3494c784594568d4135160f7e9d7dfe211d3495a 100644 (file)
@@ -322,15 +322,44 @@ function getTransientToplevel(surface)
     return null;
 }
 
+function getStyle(el, styleProp)
+{
+    if (el.currentStyle) {
+       return el.currentStyle[styleProp];
+    }  else if (window.getComputedStyle) {
+       var win = el.ownerDocument.defaultView;
+       return win.getComputedStyle(el, null).getPropertyValue(styleProp);
+    }
+    return undefined;
+}
+
+function parseOffset(value)
+{
+    var px = value.indexOf("px");
+    if (px > 0)
+       return parseInt(value.slice(0,px));
+    return 0;
+}
+
 function getFrameOffset(surface) {
-    var x = 1;
-    var y = 1;
+    var x = 0;
+    var y = 0;
     var el = surface.canvas;
     while (el != null && el != surface.frame) {
        x += el.offsetLeft;
        y += el.offsetTop;
+
+       /* For some reason the border is not includes in the offsets.. */
+       x += parseOffset(getStyle(el, "border-left-width"));
+       y += parseOffset(getStyle(el, "border-top-width"));
+
        el = el.offsetParent;
     }
+
+    /* Also include frame border as per above */
+    x += parseOffset(getStyle(el, "border-left-width"));
+    y += parseOffset(getStyle(el, "border-top-width"));
+
     return {x: x, y: y};
 }